package com.treasure.mall.zbqmallmanager.controller.statistics;

import com.treasure.mall.biz.entity.statistics.DealAmountStatisticsPO;
import com.treasure.mall.biz.entity.statistics.OrderStatisticsPO;
import com.treasure.mall.biz.service.core.statistics.DealAmountStatisticsService;
import com.treasure.mall.biz.service.core.statistics.OrderStatisticsService;
import com.treasure.mall.zbq.common.constant.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/10/11
 */
@Controller
@RequestMapping("/statistics/order")
public class OrderStatisticsController {
    @Autowired
    private DealAmountStatisticsService dealAmountStatisticsService;
    @Autowired
    private OrderStatisticsService orderStatisticsService;

    @GetMapping("/dealAmount")
    public String dealAmount(
            @RequestParam(required = false, defaultValue = "1") int pageIndex,
            @ModelAttribute("beginTime") String beginTime,
            @ModelAttribute("endTime") String endTime,
            Model model
    ) {
        Page<DealAmountStatisticsPO> page = dealAmountStatisticsService.findAll(pageIndex, Constant.DEFAULT_PAGE_SIZE, beginTime, endTime);

        model.addAttribute("pageIndex", pageIndex);
        model.addAttribute("totalRecords", page.getTotalElements());
        model.addAttribute("totalPages", page.getTotalPages());
        model.addAttribute("list", page.getContent());

        return "statistics/order_deal_amount";
    }

    @GetMapping("/count")
    public String count(
            @RequestParam(required = false, defaultValue = "1") int pageIndex,
            @ModelAttribute("beginTime") String beginTime,
            @ModelAttribute("endTime") String endTime,
            Model model
    ) {
        Page<OrderStatisticsPO> page = orderStatisticsService.findAll(pageIndex, Constant.DEFAULT_PAGE_SIZE, beginTime, endTime);

        model.addAttribute("pageIndex", pageIndex);
        model.addAttribute("totalRecords", page.getTotalElements());
        model.addAttribute("totalPages", page.getTotalPages());
        model.addAttribute("list", page.getContent());

        return "statistics/order_count";
    }
}
